<meta charset="utf-8"/>
<?php 
include '../config/DBConnect.php';

$masv=$_POST['masv'];
$phong=$_GET['mp'];
$loai=$_POST['hinhthuc'];
if ($loai==1) {
	$sql_get_date="SELECT * FROM hanthuephong";
	$rs_date=mysql_query($sql_get_date);
	$date=mysql_fetch_array($rs_date);

	$ngayhethan=$date['ngayhethan'];

	$insert="UPDATE sinhvien_phong SET maphong='$phong', ngayhethan='$ngayhethan' where masv=$masv";
	
	$query=mysql_query($insert);

	var_dump($query);
	if ($query) {
			?>
			<script type="text/javascript">
				alert("Dang ki Thanh Cong");
				self.location = "http://localhost/web-ktx/";
			</script>
			<?php
	}
		
	}else{
		$sql_get_date="SELECT * FROM hanthuephong";
		$rs_date=mysql_query($sql_get_date);
		$date=mysql_fetch_array($rs_date);

		$ngayhethan=$date['ngayhethan'];

		$insert="INSERT INTO sinhvien_phong VALUES('','$masv','$phong','$ngayhethan')";
		$query=mysql_query($insert);
		$count=1;
		if ($query) {
			$update="UPDATE phong SET sosinhvien=sosinhvien+$count where maphong='$phong'";
			$query=mysql_query($update);
			if ($query) {
				?>
				<script type="text/javascript">
					alert("Đăng ký thành công!");
					self.location = "http://localhost/web-ktx/";
				</script>
				<?php
			}


		}
	}
	?>